import request from '../../utils/request'
import {getToken} from '../../utils/token'
import qs from 'qs'
const api_name = "login"
const group_name = "oss"

/**前置准备操作*/
export function prepare() {
    return request({
        url: `/${group_name}/${api_name}/prepare`,
        method: 'get',
        headers:{
            SID: getToken("SID")
        }
    })
}

/**获取验证码 */
export function getCode() {
    return request({
        url: `/${group_name}/${api_name}/pin`,
        method: 'get',
        headers:{
            SID: getToken("SID")
        },
        responseType:"blob"
    })
}

/**获取验证码 */
export function verifyCode(code) {
    return request({
        url: `/${group_name}/${api_name}/codeverify`,
        method: 'get',
        params: { code },
        headers:{
            SID: getToken("SID")
        }
    })
}

/**用户登录 */
export function dologin(loginVo) {
    return request({
        url: `/${group_name}/${api_name}/verify`,
        method: 'post',
        data: qs.stringify({
            account:loginVo.account,
            password: loginVo.password,
            code:loginVo.code,
            encrypted:false
        }),
        headers: {
            SID: getToken("SID"),
            "Content-Type": 'application/x-www-form-urlencoded'
        }
    })
}

/** 获取用户信息*/
export function getInfo() {
    return request({
        url: `/${group_name}/${api_name}/info`,
        method: 'get',
        headers: {
            "OSS-Token": getToken("ossToken")
        }
    })
}
/** 后台用户登出*/
export function logout() {
    return request({
        url: `/${group_name}/${api_name}/logout`,
        method: 'POST',
        headers: {
            "OSS-Token": getToken("ossToken")
        }
    })
}

/**发送短信验证码 */
export function sendSMSCode(mobile) {
    return request({
        url: `/${group_name}/${api_name}/smscode/${mobile}`,
        method: 'get'
    })
}

